//
//  HJZCommentFrame.m
//  HJZWeiBo
//
//  Created by 蒋晨成 on 16/6/3.
//  Copyright © 2016年 蒋晨成. All rights reserved.
//

#import "HJZCommentFrame.h"
#import "RCLabel.h"
#import "HtmlString.h"

@implementation HJZCommentFrame

- (void)setComment:(HJZComment *)comment {
    _comment = comment;
    
    HJZUser *user = comment.user;
    
    // cell宽度
    CGFloat cellW = kWidth - HJZStatusPadding;
    // 本身大小
    CGFloat commentW = cellW;
    CGFloat commentX = 0;
    CGFloat commentY = 0;
    
    
    // 头像
    CGFloat iconXY = HJZStatusPadding;
    CGFloat iconWH = 34;
    _iconViewF = CGRectMake(iconXY, iconXY, iconWH, iconWH);

    // 昵称
    CGFloat nameX = CGRectGetMaxX(_iconViewF) + HJZStatusPadding;
    CGFloat nameY = iconXY;
    NSDictionary *nameAttributes = @{NSFontAttributeName : [UIFont systemFontOfSize:HJZStatusNameFont]};
    CGSize nameSize = [user.name sizeWithAttributes:nameAttributes];
    
    _nameBtnF = (CGRect){nameX, nameY, nameSize};
    
    //  会员
    if (user.mbtype > 0) {
        CGFloat vipX = CGRectGetMaxX(_nameBtnF) + HJZStatusPadding;
        CGFloat vipY = nameY;
        CGFloat vipW = 14;
        CGFloat vipH = nameSize.height;
        _vipViewF = CGRectMake(vipX, vipY, vipW, vipH);
    }
    
    
    
    // 时间
    CGFloat timeX = nameX;
    CGFloat timeY = CGRectGetMaxY(_nameBtnF) + HJZStatusPadding * 0.5;
    NSDictionary *timeAttributes = @{NSFontAttributeName : [UIFont systemFontOfSize:HJZStatusNameFont]};
    CGSize timeSize = [comment.created_at  sizeWithAttributes:timeAttributes];
    _timeLabelF = (CGRect){timeX, timeY, timeSize};

    // 评论内容
    NSString *commentString = nil;
    if (comment.text) {
        commentString = comment.text;
    }else {
        commentString = comment.reply_comment.text;
    }
  
    CGFloat contentX = iconXY;
    CGFloat contentY = MAX(CGRectGetMaxY(_iconViewF), CGRectGetMaxY(_timeLabelF)) + HJZStatusPadding;
    CGFloat contentMaxW = cellW - 2 * HJZStatusPadding;
    RCLabel *contentLabel = [[RCLabel alloc] initWithFrame:CGRectMake(contentX, contentY, contentMaxW, 100)];
    contentLabel.font = [UIFont systemFontOfSize:HJZStatusContentFont];
    NSString *str = [HtmlString transformString:commentString];
    contentLabel.componentsAndPlainText = [RCLabel extractTextStyle:str];
    CGSize contentSize = [contentLabel optimumSize:YES];
    _contentLabelF = (CGRect){contentX, contentY, contentSize};
    
   
    _cellHeight = CGRectGetMaxY(_contentLabelF) + HJZStatusPadding;
    _CommentViewF = CGRectMake(commentX, commentY, commentW, _cellHeight);
    
    
}


@end
